package com.ninong.ker.workflow.rest;

import com.github.pagehelper.Page;
import com.ninong.ker.admin.service.TaskService;
import com.ninong.ker.admin.service.dto.ActTaskDTO;
import com.ninong.ker.admin.service.dto.CompleteDTO;
import com.ninong.ker.common.response.CmdResponse;
import com.ninong.ker.common.tools.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 任务
 */
@RestController
@RequestMapping("cmd/v1/task")
public class TaskController {

    @Autowired
    private TaskService taskService;

    /**
     * 获取我的代办、已办任务
     *
     * @return
     */
    @PostMapping
    public ResponseEntity<CmdResponse> list(@RequestBody ActTaskDTO dto, @RequestHeader(value = Constants.TOKEN) String token) {
        CmdResponse response = new CmdResponse();
        response.setData(taskService.listPage(dto, token));
        return ResponseEntity.ok(response);
    }

    /**
     * 审批任务
     *
     * @return
     */
    @PutMapping
    public ResponseEntity<CmdResponse> apply(@RequestBody CompleteDTO dto) {
        taskService.applyTask(dto);
        return ResponseEntity.ok(new CmdResponse());
    }
}
